﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Level65.ClipShow;

namespace clipShowConfig
{
    public partial class frmMain : Form
    {
        
        private Settings _myplugInSettings;
        public frmMain()
        {
            InitializeComponent();

            Storage st = new Storage();
            _myplugInSettings = st.GetSettings();

            foreach (string fileType in _myplugInSettings.MediaTypes)
            {
                lbMediaFileTypes.Items.Add(fileType);
            }
        }

        private void removeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string s = (string)lbMediaFileTypes.SelectedItem;
            lbMediaFileTypes.Items.Remove(s);
            btnApply.Enabled = true;
        }

        private void addToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MediaType mt = new MediaType();
            mt.ShowDialog();

            string result = mt.txtFileTypeExtension.Text.ToString();

            if (!result.Equals("cancel"))
            {
                lbMediaFileTypes.Items.Add(result);
                btnApply.Enabled = true;
            }
        }

        private void btnApply_Click(object sender, EventArgs e)
        {
            try
            {
                string[] results = new string[lbMediaFileTypes.Items.Count];
                int Ctr = 0;
                foreach (string s in lbMediaFileTypes.Items)
                {
                    results[Ctr] = s;
                    Ctr++;
                }

                _myplugInSettings.MediaTypes = results;

                Storage st = new Storage();
                st.PersistSettings(_myplugInSettings);

                MessageBox.Show("Changes have been saved.", "clipShow Configuration", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.Close();
            }
            catch (SystemException se)
            {
                MessageBox.Show(se.Message, "clipShow Configuration", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
